<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>无标题文档</title>
<script type="text/javascript">

var str = "欢迎来到广科院"; 
var reg = new RegExp("广科","g");
var result;

while ((result = reg.exec(str)) != null)  {
  document.write(result);
  document.write("<br />");
  document.write(reg.lastIndex);
 }
</script>

</head>

<body>
</body>
</html>
